package org.springframework.samples.countries.web.translate;

import java.util.List;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.EmptyVisitor;

import pikes.ecma.SourceElement;
import pikes.ecma.SourceElements;

public class EventHandlerTranslator extends EmptyVisitor implements TranslationResultProcessor {

	private SourceElements sourceElements = null;

	private String methodName = null;

	public EventHandlerTranslator(String methodName, SourceElements sourceElements) {
		super();
		this.methodName = methodName;
		this.sourceElements = sourceElements;
	}

	@Override
	public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
		if (methodName.equals(name)) {
			return new MethodBlockTranslator(name, 0, this);
		}
		else {
			return null;
		}

	}

	public void processResult(List<String> parameters, SourceElement functionBody) {
		sourceElements.add(functionBody);
	}
}
